package com.hxgz.steel.controller.common;

import com.hxgz.steel.common.Const;
import com.hxgz.steel.common.ResponseCode;
import com.hxgz.steel.common.ServerResponse;
import com.hxgz.steel.controller.portal.UserContorller;
import com.hxgz.steel.domain.User;
import com.hxgz.steel.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author 刘桓
 * @Date 16:32 2019/3/28
 * @Description
 */
@RestController
@RequestMapping("Common")
@Api(tags = "checkRole", description = "公共接口:核查人员角色")
@Slf4j
//@CrossOrigin
public class CheckRoleController {

  private static final Logger logger = LoggerFactory.getLogger(CheckRoleController.class);
  @Autowired
  public UserService uService;

  @RequestMapping(value = "checkRole.do", method = RequestMethod.POST)
  @ApiOperation("此方法弃用!!!核查人员信息:roleStatus 0未认证用户  1已认证用户，未认证店铺  2已认证用户，已认证店铺  3已认证用户，已认证公司,店铺已禁用")
  public ServerResponse checkRole(HttpServletRequest httpServletRequest, HttpSession session) {
    logger.info("核查人员信息获取session的id ------------- " + session.getId());
    Cookie[] cookie = httpServletRequest.getCookies();
//    for(int i=0;i<cookie.length;i++){
//      logger.info("核查人员信息获取cookies -"+i+"------------ "+ cookie[i].getName()+" == "+cookie[i].getValue());
//    }
    User user = Const.checkUserLogin(httpServletRequest);
    if (user == null) {
      user = new User();
    }
    //核查人员是否实名，店铺是否实名
    return uService.getUserRole(user.getId());
  }

  @RequestMapping(value = "checkUserStatus.do", method = RequestMethod.POST)
  @ApiOperation("0未登陆1已登陆但未认证用户2已认证用户但未认证店铺未认证公司3已认证用户已认证公司但未认证店铺4已认证用户已认证公司已认证店铺")
  public ServerResponse checkUserStatus(HttpServletRequest httpServletRequest) {
    User user = Const.checkUserLogin(httpServletRequest);
    if (user == null) {
      return ServerResponse.createBySuccess(0);
    }
    return uService.checkUserStatus(user.getId());
  }


}
